package com.secondriver.url.filter.match.groovy

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap

import com.secondriver.url.filter.match.URLCacheObject
import com.secondriver.url.filter.match.URLPatternMatch;
import com.secondriver.url.filter.urlrealm.Subject;

/**
 * 默认URL模式匹配属于完整精确匹配
 * 
 * @author ZhangXiao
 *
 */
class DefalutURLPatternMatch implements URLPatternMatch {

	@Override
	public boolean isPass(String requestURI, Set<String> urls) {
		return urls.any { it->

			requestURI=fixedUrlPrefix(requestURI);
			it=fixedUrlPrefix(it);

			return requestURI.equals(it);
		};
	}

	def static String fixedUrlPrefix(String url){
		return url.startsWith(DEFAULT_PATH_SEPARATOR) ? url:DEFAULT_PATH_SEPARATOR+url;
	}

	def static boolean isEmpty(String url){
		return null==url || url.trim().size() ==0;
	}

	def static String[] splitUrlToParts(String url){
		return url.split(DEFAULT_PATH_SEPARATOR).findAll{ it->
			return !DefalutURLPatternMatch.isEmpty(it);
		}
	}

	def static String CHARACTER="[\\w-.?%&=]";
}